﻿using System;
using Autofac.Extensions.DependencyInjection;
using Infrastructure;
using Infrastructure.Helpers;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

namespace OpenAuth.WebApi
{
    public class Program
    {
        public static void Main(string[] args)
        {
            Console.WriteLine($@"
            -------------------------------------------------------------------
                        __        _______ ____    _    ____ ___ 
                        \ \      / / ____| __ )  / \  |  _ \_ _|
                         \ \ /\ / /|  _| |  _ \ / _ \ | |_) | | 
                          \ V  V / | |___| |_) / ___ \|  __/| | 
                           \_/\_/  |_____|____/_/   \_\_|  |___|  


            -------------------------------------------------------------------
            Start Time:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
            CreateHostBuilder(args).Build().Run();
        }

        public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .ConfigureLogging((hostingContext, logging) =>
                {
                    logging.ClearProviders(); //去掉默认的日志
                })
                .UseServiceProviderFactory(
                    new AutofacServiceProviderFactory()) //将默认ServiceProviderFactory指定为AutofacServiceProviderFactory
                .ConfigureWebHostDefaults(webBuilder =>
                {
                    var configuration = ConfigHelper.GetConfigRoot();
                    var httpHost = configuration["AppSetting:HttpHost"];

                    //设置文件上传大小（最大支持200M）
                    webBuilder.UseUrls(httpHost).ConfigureKestrel(options =>
                    {
                        options.Limits.MaxRequestBodySize = 200 * 1024 * 1024;
                    });

                    webBuilder.UseUrls(httpHost).UseStartup<Startup>();

                    Console.WriteLine($"启动成功，接口访问地址:{httpHost}/swagger/index.html");
                });
    }
}